// SelectorTable.cpp: implementation of the SelectorTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SelectorTable.h"
#include "SelectorTableRecord.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define GET_FUNCTION(A,B,C) \
	if( !this->m_pCurRecord ) \
	{ \
		return this->m_ResPtr->A(C);\
	}\
	else\
	{\
		return this->m_pCurRecord->B();\
	}

namespace PDMS
{
	namespace PDMSDBIF
	{
		BEGIN_REGISTER_MAP( SelectorTable, MultiRecordsDatabaseElement)
			REGISTER( _T("selector"), GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) )
		END_REGISTER_MAP();
		SelectorTable::SelectorTable()
		{
		}
		
		SelectorTable::~SelectorTable()
		{

		}

		unsigned long SelectorTable::GetID() const
		{
			GET_FUNCTION( GetLong,GetID,"ID" )
		}
		
		void SelectorTable::SetParentID(unsigned long parentID)
		{	
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetParentID(parentID);
		}
		unsigned long SelectorTable::GetParentID() const
		{
			GET_FUNCTION( GetLong,GetParentID,"ParentID" )
		}

		void SelectorTable::SetID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetID( lID );
		}

		const StdString SelectorTable::GetSpecName() const
		{
			GET_FUNCTION( GetString,GetSpecName,"SPECNAME" )
		}

		void SelectorTable::SetSpecName( const StdString &strName )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetSpecName( strName );
		}

		const StdString SelectorTable::GetName() const
		{
			GET_FUNCTION( GetString,GetName,"NAME" )
		}

		void SelectorTable::SetName( const StdString& strName )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetName( strName );
		}

		double SelectorTable::GetPbor0() const
		{
			GET_FUNCTION( GetDouble,GetPbor0,"PBOR0" )
		}

		void SelectorTable::SetPbor0( double d )
		{
			ASSERT( this->m_pCurRecord );
		//	ASSERT( d > 0 );
			this->m_pCurRecord->SetPbor0( d );
		}

		double SelectorTable::GetPbor1() const
		{
			GET_FUNCTION( GetDouble,GetPbor1,"PBOR1" )
		}

		void SelectorTable::SetPbor1( double d )
		{
			ASSERT( this->m_pCurRecord );
		//	ASSERT( d > 0 );
			this->m_pCurRecord->SetPbor1( d );
		}

		double SelectorTable::GetPbor2() const
		{
			GET_FUNCTION( GetDouble,GetPbor2,"PBOR2" )
		}

		void SelectorTable::SetPbor2( double d )
		{
			ASSERT( this->m_pCurRecord );
		//	ASSERT( d > 0 );
			this->m_pCurRecord->SetPbor2( d );
		}

		double SelectorTable::GetPbor3() const
		{
			GET_FUNCTION( GetDouble,GetPbor3,"PBOR3" )
		}
		
		void SelectorTable::SetPbor3( double d )
		{
			ASSERT( this->m_pCurRecord );
			//ASSERT( d > 0 );
			this->m_pCurRecord->SetPbor3( d );
		}
		
		const StdString SelectorTable::GetGType() const
		{
			GET_FUNCTION( GetString,GetGType,"TYPE" )
		}
		
		void SelectorTable::SetGType( const StdString& strGTye )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetGType( strGTye );
		}
		
		const StdString SelectorTable::GetSType() const
		{
			GET_FUNCTION( GetString,GetSType,"STYPE" )
		}
		
		void SelectorTable::SetSType( const StdString& strSTye )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetSType( strSTye );
		}
		
		const StdString SelectorTable::GetEdge() const
		{
			GET_FUNCTION( GetString,GetEdge,"EDGE" )
		}
		
		void SelectorTable::SetEdge( const StdString& strEdge )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetEdge( strEdge );
		}
		
		BOOL SelectorTable::GetAllo() const
		{
			GET_FUNCTION( GetBool,GetAllo,"ALLO" )
		}
		
		void SelectorTable::SetAllo( BOOL b )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetAllo( b );
		}
		
		BOOL SelectorTable::GetShop() const
		{
			GET_FUNCTION( GetBool,GetShop,"SHOP" )
		}
		
		void SelectorTable::SetShop( BOOL b )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetShop( b );
		}
		
		double SelectorTable::GetAngle() const
		{
			GET_FUNCTION( GetDouble,GetAngle,"ANGLE" )
		}
		
		void SelectorTable::SetAngle( double d )
		{
			ASSERT( this->m_pCurRecord );
		//	ASSERT( d > 0 );
			this->m_pCurRecord->SetAngle( d );
		}
		
		const StdString SelectorTable::GetCATAMDBDir() const
		{
			GET_FUNCTION( GetString,GetCATAMDBDir,"CATAMDBDIR" )
		}
		
		void SelectorTable::SetCATAMDBDir( const StdString& strDir )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetCATAMDBDir( strDir );
		}
		
		const StdString SelectorTable::GetComponentDir() const
		{
			GET_FUNCTION( GetString,GetComponentDir,"ComponentDir" )
		}
		
		void SelectorTable::SetComponentDir( const StdString& strDir )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetComponentDir( strDir );
		}
		
		const StdString SelectorTable::GetBoltDir() const
		{
			GET_FUNCTION( GetString,GetBoltDir,"BoltDir" )
		}
		
		void SelectorTable::SetBoltDir( const StdString& strDir )
		{
			ASSERT( this->m_pCurRecord );
			this->m_pCurRecord->SetBoltDir( strDir );
		}
		
		unsigned long SelectorTable::GetComponentID() const
		{
			GET_FUNCTION( GetLong,GetComponentID,"ComponentID" )
		}

		void SelectorTable::SetComponentID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetComponentID( lID );
		}
		
		unsigned long SelectorTable::GetBOLTID() const
		{
			GET_FUNCTION( GetLong,GetBOLTID,"SBOL" )
		}

		void SelectorTable::SetBOLTID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetBOLTID( lID );
		}

		unsigned long SelectorTable::GetSCOMID() const
		{
			GET_FUNCTION( GetLong,GetSCOMID,"SCOM" )
		}

		void SelectorTable::SetSCOMID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetSCOMID( lID );
		}

		unsigned long SelectorTable::GetSDTEID() const
		{
			GET_FUNCTION( GetLong,GetSDTEID,"SDTE" )
		}

		void SelectorTable::SetSDTEID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetSDTEID( lID );
		}

		unsigned long SelectorTable::GetMTEXID() const
		{
			GET_FUNCTION(GetLong,GetMTEXID,"MTEX")
		}

		void SelectorTable::SetMTEXID( unsigned long lID )
		{
			ASSERT( m_pCurRecord );
			this->m_pCurRecord->SetMTEXID( lID );
		}

		void SelectorTable::SetData( RecordPtr_ ptr )
		{
			ASSERT( ptr != NULL );

			if ( ptr->IsAlloModified() )
			{
				this->m_ResPtr->SetBool( _T("ALLO"),ptr->GetAllo() );
			}

			if ( ptr->IsAngleModified() )
			{
				this->m_ResPtr->SetDouble( _T("ANGLE"),ptr->GetAngle() );
			}

			if ( ptr->IsBoltDirModified() )
			{
				this->m_ResPtr->SetString( _T("BoltDir"),ptr->GetBoltDir() );
			}

			if ( ptr->IsBoltIDModified() )
			{
				this->m_ResPtr->SetLong( _T("SBOL"),ptr->GetBOLTID() );
			}

			if ( ptr->IsCATAMDBDirModified() )
			{
				this->m_ResPtr->SetString( _T("CATAMDBDIR"),ptr->GetCATAMDBDir() );
			}

			if ( ptr->IsComponentDirModified() )
			{
				this->m_ResPtr->SetString( _T("ComponentDir"),ptr->GetComponentDir() );
			}

			if ( ptr->IsComponentIDModified() )
			{
				this->m_ResPtr->SetLong( _T("ComponentID"),ptr->GetComponentID() );
			}
			
			if ( ptr->IsEdgeModified() )
			{
				this->m_ResPtr->SetString( _T("EDGE"),ptr->GetEdge() );
			}
			
			if ( ptr->IsGTypeModified() )
			{
				this->m_ResPtr->SetString( _T("TYPE"),ptr->GetGType() );
			}

			if ( ptr->IsIDModified() )
			{
				this->m_ResPtr->SetLong( _T("ID"),ptr->GetID() );
			}
			
			if ( ptr->IsParentIDModified() )
			{
				this->m_ResPtr->SetLong( _T("ParentID"), ptr->GetParentID() );
			}

			if ( ptr->IsMTEXIDModified() )
			{
				this->m_ResPtr->SetLong( _T("MTEX"),ptr->GetMTEXID() );
			}

			if ( ptr->IsNameModified() )
			{
				this->m_ResPtr->SetString( _T("NAME"),ptr->GetName() );
			}

			if ( ptr->IsPbor0Modified() )
			{
				this->m_ResPtr->SetDouble( _T("PBOR0"),ptr->GetPbor0() );
			}

			if ( ptr->IsPbor1Modified() )
			{
				this->m_ResPtr->SetDouble( _T("PBOR1"),ptr->GetPbor1() );
			}

			if ( ptr->IsPbor2Modified() )
			{
				this->m_ResPtr->SetDouble( _T("PBOR2"),ptr->GetPbor2() );
			}

			if ( ptr->IsPbor3Modified() )
			{
				this->m_ResPtr->SetDouble( _T("PBOR3"),ptr->GetPbor3() );
			}

			if ( ptr->IsSCOMIDModified() )
			{
				this->m_ResPtr->SetLong( _T("SCOM"),ptr->GetSCOMID() );
			}

			if ( ptr->IsSDTEIDModified() )
			{
				this->m_ResPtr->SetLong( _T("SDTE"),ptr->GetSDTEID() );
			}

			if ( ptr->IsShopModified() )
			{
				this->m_ResPtr->SetBool( _T("SHOP"),ptr->GetShop() );
			}

			if ( ptr->IsSpecNameModified() )
			{
				this->m_ResPtr->SetString( _T("SPECNAME"),ptr->GetSpecName() );
			}

			if ( ptr->IsSTypeModified() )
			{
				this->m_ResPtr->SetString( _T("STYPE"),ptr->GetSType() );
			}
		}
		StdString SelectorTable::GetOpenSQL( const StdString& strCondition )
		{
			StdString strTemp( _T("Select * from selector ") );
			if ( strCondition == ALLRECORD )
			{
				return strTemp;
			}

			return strTemp + _T("Where ") + strCondition;
		}
	}
}




